﻿using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CadDotNetTools
{
    public static class HightlightEntitiesTools
    {
        /// <summary>
        /// 高亮
        /// </summary>
        /// <param name="ids"></param>
        public static void HightlightEntities(this ObjectIdCollection ids)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            using (var trans = doc.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ids)
                {
                    var ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                    if (ent != null) ent.Highlight();  //高亮
                }
                trans.Commit();
            }
        }
        /// <summary>
        /// 高亮
        /// </summary>
        /// <param name="ids"></param>
        public static void HightlightEntities(this Document doc, params ObjectId[] ids)
        {
            //var doc = Application.DocumentManager.MdiActiveDocument;
            using (var trans = doc.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ids)
                {
                    var ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                    if (ent != null) ent.Highlight();  //高亮
                }
                trans.Commit();
            }
        }
        /// <summary>
        /// 取消高亮
        /// </summary>
        /// <param name="ids"></param>
        public static void UnHightlightEntities(this ObjectIdCollection ids)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            using (var trans = doc.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ids)
                {
                    var ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                    if (ent != null) ent.Unhighlight();  //取消高亮
                }
                trans.Commit();
            }
        }

        /// <summary>
        /// 取消高亮
        /// </summary>
        /// <param name="ids"></param>
        public static void UnHightlightEntities(this Document doc, params ObjectId[] ids)
        {
            //var doc = Application.DocumentManager.MdiActiveDocument;
            using (var trans = doc.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in ids)
                {
                    var ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                    if (ent != null) ent.Unhighlight();  //取消高亮
                }
                trans.Commit();
            }
        }
    }
}
